package com.ckh.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ckh.springboot.common.Result;
import com.ckh.springboot.entity.SysAnnouncement;
import com.ckh.springboot.entity.ExamSchedule;
import com.ckh.springboot.service.ISysAnnouncementService;
import com.ckh.springboot.service.IExamScheduleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/dashboard")
@CrossOrigin(origins = "http://localhost:9528")
public class DashboardController {

    @Resource
    private ISysAnnouncementService sysAnnouncementService;
    
    @Resource
    private IExamScheduleService examScheduleService;

    @GetMapping("/info")
    public Result getDashboardInfo() {
        // 获取启用状态的公告
        List<SysAnnouncement> announcements = sysAnnouncementService.list(
            new LambdaQueryWrapper<SysAnnouncement>()
                .eq(SysAnnouncement::getStatus, 1)
                .orderByDesc(SysAnnouncement::getCreateTime)
        );
        
        // 获取启用状态的考试安排
        List<ExamSchedule> examSchedules = examScheduleService.list(
            new LambdaQueryWrapper<ExamSchedule>()
                .eq(ExamSchedule::getStatus, 1)
                .orderByAsc(ExamSchedule::getExamTime)
        );
        
        Map<String, Object> data = new HashMap<>();
        data.put("announcements", announcements);
        data.put("examSchedules", examSchedules);
        
        return Result.success(data);
    }
}